/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.service.impl;

import com.rbh.risk.dao.OpduserDao;
import com.rbh.risk.dao.ProfileDao;
import com.rbh.risk.entity.Opduser;
import com.rbh.risk.entity.Profile;
import com.rbh.risk.service.ProfileService;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("profileService")
public class ProfileServiceImpl implements ProfileService {

    private final static Logger logger = Logger.getLogger(ProfileService.class);
    @Autowired
    private ProfileDao profileDao;
    @Autowired
    private OpduserDao opduserDao;

    @Transactional(readOnly = false)
    @Override
    public void insert(Profile profile) {
        this.profileDao.insert(profile);
    }

    @Transactional(readOnly = false)
    @Override
    public void update(Profile profile) {
        this.profileDao.update(profile);
    }

    @Transactional(readOnly = false)
    @Override
    public void delete(Profile profile) {
        this.profileDao.delete(profile);
    }

    @Transactional(readOnly = true)
    @Override
    public Profile getById(String profileId) {
        return this.profileDao.getById(profileId);
    }

    @Transactional(readOnly = true)
    @Override
    public List<Profile> getAll() {
        List<Profile> results = null;
        try {
            results = this.profileDao.getAll();
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
        return results;
    }

    @Transactional(readOnly = false)
    @Override
    public Profile insertAutomatic(Opduser opduser) {
        Profile result = null;
        try {
            Profile profile = new Profile();
            profile.setProfileStatus(true);
            profile.setOpduser(opduser);

            result = this.profileDao.insertAutomatic(profile);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
        return result;
    }

    @Transactional(readOnly = true)
    @Override
    public Profile getByOpduser(Opduser opduser) {
        return this.profileDao.getByOpduser(opduser);
    }

    @Transactional(readOnly = true)
    @Override
    public List<Opduser> getByWordOfOpduser(String words) {
        return this.opduserDao.getByWords(words);
    }
}